package thread;
/**
 * 通过runnable接口创建线程
 * @author HXZY
 *
 */
public class RunableDemo implements Runnable{
	private Ticks ticks=new Ticks();

	@Override
	public void run() {
		int b=0;
		
		while(true){
			synchronized (ticks) {
				if (ticks.getT() <= 0)
					break;
				ticks.sail();
			}
			//		while(true){
//			synchronized (this) {
//				if (a <= 0)
//					break;
//				a--;
//			}
			b++;
			try {
				Thread.sleep(10);				
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
					
			}
		System.out.println
		("我是售票窗"+Thread.currentThread().getName()
				+"卖了"+b+"张票"+"还剩下"+ticks.getT()+"张票");
		}
	}

class Ticks{
	private int t=100;

	public int getT() {
		return t;
	}

	public void sail() {
		t --;
	}

	
}


